package com.chenguo.testRabbit.product;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

/**
 * @author 小66
 * @date 2020-06-22 20:04
 **/
@RestController
public class TopicProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/topicExchange")
    public void topicExchange() {

        String msg1 = "I am topic.message msg======";

        System.out.println("topicSender1 : " + msg1);

        this.rabbitTemplate.convertAndSend("topicExchange", "topic.message", msg1);

        String msg2 = "I am topic.messages2222 msg########";

        System.out.println("topicSender2 : " + msg2);

        this.rabbitTemplate.convertAndSend("topicExchange", "topic.messages", msg2);

    }

    @GetMapping("/topicExchange2")
    public void topicExchange2() {


        String msg1 = "I am topic.message msg======";

        System.out.println("topicSender : " + msg1);


        for (int i = 0; i < 10; i++) {
            if(i%2 ==0){
                this.rabbitTemplate.convertAndSend("topicExchange", "topic.#", msg1);


            }else {
                //this.rabbitTemplate.convertAndSend("topicExchange1", "topic.#", msg1);


            }

        }


//        String msg2 = "I am topic.messages2222 msg########";
//
//        System.out.println("topicSender2 : " + msg2);
//
//        this.rabbitTemplate.convertAndSend("topicExchange", "topic.messages", msg2);

    }
}
